package swind.web.entities;
// Generated 2016-10-11 23:28:29 by Hibernate Tools 4.3.1.Final

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * ExamUser generated by hbm2java
 */
@Entity
@Table(name = "exam_user")
public class ExamUser implements java.io.Serializable {
	
	private static final long serialVersionUID = -8959650035071785541L;
	
	private String userId;
	private String userName;
	private String password;
	private String tel;
	private String email;
	private String address;
	private Date birthday;
	private int gender;
	private Date lastLockTime;
	private byte loginFailCount;
	
	private Set<ExamRole> examRoles=new HashSet<ExamRole>();
	private Set<ExamSubject> examSubjects=new HashSet<ExamSubject>();

	public ExamUser() {
	}
	
	
	
	public ExamUser(String userId, String userName) {
		super();
		this.userId = userId;
		this.userName = userName;
	}



	@Id
	//@GeneratedValue(strategy = IDENTITY)
	@Column(name = "user_id", unique = true, nullable = false, length = 10)
	public String getUserId() {
		return this.userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	@Column(name = "user_name", nullable = false, length = 45)
	public String getUserName() {
		return this.userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column(name = "password", nullable = false)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "tel", length = 20)
	public String getTel() {
		return this.tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	@Column(name = "email")
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "address")
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "birthday", nullable = false, length = 10)
	public Date getBirthday() {
		return this.birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(name = "gender", nullable = false)
	public int getGender() {
		return this.gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "last_lock_time", length = 19)
	public Date getLastLockTime() {
		return this.lastLockTime;
	}

	public void setLastLockTime(Date lastLockTime) {
		this.lastLockTime = lastLockTime;
	}

	@Column(name = "login_fail_count")
	public byte getLoginFailCount() {
		return this.loginFailCount;
	}

	public void setLoginFailCount(byte loginFailCount) {
		this.loginFailCount = loginFailCount;
	}
	
	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinTable(name="exam_user_role",joinColumns={@JoinColumn(name="user_id")},inverseJoinColumns={@JoinColumn(name="role_id")})
	public Set<ExamRole> getExamRoles() {
		return examRoles;
	}

	public void setExamRoles(Set<ExamRole> examRoles) {
		this.examRoles = examRoles;
	}
	
	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinTable(name="exam_user_subject",joinColumns={@JoinColumn(name="user_id")},inverseJoinColumns={@JoinColumn(name="sub_id")})
	public Set<ExamSubject> getExamSubjects() {
		return examSubjects;
	}

	public void setExamSubjects(Set<ExamSubject> examSubjects) {
		this.examSubjects = examSubjects;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ExamUser other = (ExamUser) obj;
		if (userId == null) {
			if (other.userId != null)
				return false;
		} else if (!userId.equals(other.userId))
			return false;
		return true;
	}
	
	
	

}
